package org.utils.cmdline.parameters;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class MultiValueParameter extends NonTerminalParameter {

    private String value[];

//accessing
    public String[] values() {
		return value;
    }

    public void values(String[] aValue) {
		value = aValue;
    }

    public void valueAt(int index, String aValue) {
		values()[index] = aValue;
    }

//constants
    public String[] defaultValue(int length) {
		return newStringArray(length);
    }

//action
    public void loadAdditionalArguments(Iterator iterator) {
	super.loadAdditionalArguments(iterator);
	try {
	for (int index = 0; index < parameterLength();index++) {
	    valueAt(index,(String)iterator.next());
	}
	} catch (NoSuchElementException exception) {
	    terminalDealWithException(exception); }
    }

//construction
    public MultiValueParameter(int additionalParameterLength) {
		super(additionalParameterLength);
		throwExceptionWhen(
			additionalParameterLength <=1,
			new IllegalArgumentException( "Multi Value Parameters must have length > 1")
		);
		values(defaultValue(additionalParameterLength));
    }

}

